package com.bestcem.xm.user.grpc.client.convert;

import com.bestcem.bp.pay.grpc.v1.services.CreateMiniProgramOrderResponse;
import com.bestcem.bp.pay.grpc.v1.services.Order;
import com.bestcem.xm.user.grpc.client.convert.strategy.OrderGrpcConvertStrategy;
import com.bestcem.xm.user.grpc.client.dto.OrderDTO;
import com.bestcem.xm.user.service.dto.order.WalletOrderDTO;
import com.bestcem.xm.user.service.dto.order.WeChatOrderDTO;
import com.bestcem.xm.user.util.business.mapstract.TransformStrategy;
import com.bestcem.xm.user.util.business.mapstract.TransformStrategyConstant;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;

/**
 * 订单相关转换类
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/20 11:28
 */
@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface OrderGrpcConvert extends OrderGrpcConvertStrategy, TransformStrategy {

    @Mapping(target = "orderId", source = "orderNo")
    @Mapping(target = "paySignature", source = "paySign")
    WeChatOrderDTO response2WechatOrderDTO(CreateMiniProgramOrderResponse response);

    Order walletOrderDTO2Order(WalletOrderDTO orderDTO);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "payMethod", source = "payMethodValue")
    @Mapping(target = "type", source = "typeValue")
    @Mapping(target = "status", source = "statusValue")
    @Mapping(target = "payConfirmed", source = "payConfirmed", qualifiedByName = TransformStrategyConstant.BOOLEAN_TO_INTEGER)
    @Mapping(target = "payTime", source = "payTime", qualifiedByName = TransformStrategyConstant.GRPC_TIMESTAMP_TO_DATE)
    @Mapping(target = "createTime", source = "baseTime.createTime", qualifiedByName = TransformStrategyConstant.GRPC_TIMESTAMP_TO_DATE)
    @Mapping(target = "updateTime", source = "baseTime.updateTime", qualifiedByName = TransformStrategyConstant.GRPC_TIMESTAMP_TO_DATE)
    OrderDTO order2OrderDTO(Order order);

    @Mapping(target = "payConfirmed", source = "payConfirmed", qualifiedByName = TransformStrategyConstant.INTEGER_TO_BOOLEAN)
    @Mapping(target = "payTime", source = "payTime", qualifiedByName = TransformStrategyConstant.DATE_TO_GRPC_TIMESTAMP)
    @Mapping(target = "baseTime.createTime", source = "createTime", qualifiedByName = TransformStrategyConstant.DATE_TO_GRPC_TIMESTAMP)
    @Mapping(target = "baseTime.updateTime", source = "updateTime", qualifiedByName = TransformStrategyConstant.DATE_TO_GRPC_TIMESTAMP)
    Order orderDTO2Order(OrderDTO orderDTO);
}
